#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 1e3 + 5;

const int maxn2 = 2e4 + 5;

int w[maxn], v[maxn], s[maxn];
int dp[maxn2];
int n, V;

void solve(){
	cin >> n >> V;
	for (int i=1;i<=n;i++) {
		cin >> w[i] >> v[i] >> s[i];
	}
	for (int i=1;i<=n;i++) {
		int sm = 0;
		for (int k=1;k<=s[i] && sm < s[i];k*=2) {
			k = min(k, s[i]-sm); // 最后剩余的元素一组
			for (int j=V;j>=1;j--) {
				if (j >= (w[i]*k)) {
					dp[j] = max(dp[j], dp[j-(w[i]*k)] + v[i]*k);					
				}
			}
			sm += k;
		}
	}
	
	int ans = 0;
	for (int i=1;i<=V;i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << '\n';
}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
